package com.wyh;

import com.wyh.bean.ConsumerComponent;
import com.wyh.util.Consume;
import com.wyh.util.Report;
import org.apache.dubbo.config.spring.context.annotation.EnableDubbo;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;

import java.io.IOException;
import java.util.concurrent.Executor;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;

/**
 * @author wuyuhan
 * @date 2021/1/26 21:57
 */
public class AnnotationConsumerMain {
    public static void main(String[] args) throws IOException, InterruptedException {
        AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(ConsumerConfiguration.class);
        context.start();
        //输出运行结果
        Executors.newSingleThreadScheduledExecutor().scheduleWithFixedDelay(new Report(), 5, 5, TimeUnit.SECONDS);

        //创建线程池进行调用服务
        ConsumerComponent service = context.getBean(ConsumerComponent.class);
        Executor executor1 = Executors.newFixedThreadPool(10);
        executor1.execute(new Consume(service, "A"));
        executor1.execute(new Consume(service, "B"));
        executor1.execute(new Consume(service, "C"));
    }

    @Configuration
    @PropertySource("classpath:/dubbo-consumer.properties")
    @ComponentScan("com.wyh.bean")
    @EnableDubbo
    static class ConsumerConfiguration {

    }
}
